
Ext.define('js.basicInformation.BasGraphAddWindow', {
    extend: 'Ext.grid.Panel',
    requires: ['js.Util', 'js.ctrl.Common'],
    controller: 'Common',
    id: 'BasGraphAddWindow',
    margin:'0 20 20 20',
    initComponent: function () {
        this.store = Ext.create('js.store.user.BasGraphAddWindowListStore');
        this.columns = [
            {text: 'ID', align: util.gridContainerAlign, dataIndex: 'user_id', flex: 1, hidden:true},
            {text: '用户名称', align: util.gridContainerAlign, dataIndex: 'user_name', flex: 1}
        ];
        this.dockedItems = [
            {dock: 'top',
                xtype: 'panel',
                ui: 'threshold1',
                height:120,
                width: '100%',
                border: false,
                layout: {
                    type: 'hbox',
                    align: 'stretch',
                },
                items: [
                    {
                        xtype: 'panel',
                        height: '100%',
                        width:'50%',
                        margin:'20 0 0 0',
                        items:[{
                            xtype: 'component',
                            html: `<span class="white-font-smallA">请选择班组：</span>`,
                            margin: '10 50 10 0',
                            width:'50%'
                        },{
                            xtype: 'combobox',
                            height: 20,
                            emptyText: '请选择班组',
                            width: '100%',
                            labelSeparator: '',
                            labelWidth: 70,
                            editable: false,
                            value:'全部',
                            displayField: 'dataType',
                            valueField: 'value',
                            store:  Ext.create('js.store.user.groupUserStore'),
                            listeners: {
                                afterrender: function (combo) {
                                    combo.setValue("all");

                                },
                                change:function (com, newValue, oldValue, eOpts) {//企业ID
                                    let me = Ext.getCmp('BasGraphAddWindow');
                                    me.store.getProxy().setExtraParam('group_id', newValue);
                                    me.store.reload();
                                }
                            }

                        }]
                    }
                ]},{
                dock: 'top',
                xtype: 'toolbar',
                id:'toolbarfp',
                border:false,
                padding:'10 0 10 0',
                style:{
                    background:'#fff'
                },
                items: [{
                    xtype : "button",
                    height:'40',
                    width:100,
                    cls:'buttonAA',
                    text: '<span style="color:#fff;font-size:18px;">分配</span>',
                    handler: this.distribute,
                    idA:this.idA,
                    nameA:this.nameA,
                    action_Type:this.actionType,
                    scope: this,
                },{
                    text: '<span style="color:#fff;font-size:18px;">刷新</span>',
                    name: 'btnRefresh',
                    height:'40',
                    width:100,
                    cls:'buttonAA',
                    handler: this.refresh,
                    scope: this
                }]
            }];
        this.selModel = Ext.create('Ext.selection.CheckboxModel', {mode: 'MULTI', pruneRemoved: false,text: '全选'});
        this.callParent(arguments);
    },
    distribute: function (btn) {  //分配设备
        let resultSelection = this.getSelection();
        if (resultSelection.length <= 0) {
            Ext.toast('请选择需要分配的设备！');
            return;
        }
        let arrIds = [];
        let ids = Ext.Array.map(resultSelection, (item) => {
            arrIds.push(item.get('user_id'));
        });
        let arrNameS=[];
        let name = Ext.Array.map(resultSelection, (item) => {
            arrNameS.push(item.get('user_name'));
        });
        let idlength=arrIds.length;
        if(btn.action_Type == 'dan'){
            if(idlength>1){
                Ext.toast('责任监督员为唯一值');

            }else{
                Ext.getCmp(btn.idA).setValue(arrIds);
                Ext.getCmp(btn.nameA).setValue(arrNameS);
                btn.up('window').close();
            }

        }else{
            Ext.getCmp(btn.idA).setValue(arrIds);
            Ext.getCmp(btn.nameA).setValue(arrNameS);
            btn.up('window').close();
        }

    },
    refresh:function(){
        this.getStore().reload();
    },
    operatorSuccess: function (response) {
        let obj = Ext.decode(response.responseText);
        if (obj.success) {
            Ext.toast('分配成功');
            let RealTimeAlarmPanel=Ext.getCmp('js.home.RealTimeAlarmPanel');
            clearInterval( RealTimeAlarmPanel.interval);
            for(let i = 0 ;i<RealTimeAlarmPanel.alarmTittleList.length;i++){
                clearInterval(RealTimeAlarmPanel.alarmTittleList[i].topInterval);
                clearInterval(RealTimeAlarmPanel.alarmTittleList[i].bottomInterval)
            }
            RealTimeAlarmPanel.alarmTittleList=[];
            Ext.getCmp('BasGraphAddWindow').up().close();
            RealTimeAlarmPanel.remove();
            RealTimeAlarmPanel.createRealTimeAlarm();
            RealTimeAlarmPanel.createInterval();

        } else {
            Ext.toast(obj.message);
        }
    }
    ,
    operatorFail: function (response) {
        Ext.toast(`分配失败：${response.status}`);
    }
});